package base {
	
	import base.constants.Colors;
	import flash.display.Shape;
	import flash.filters.GlowFilter;

	public class GShape extends Shape
	{
		
		public static const Rect:uint = 0;
		public static const Circ:uint = 1;
		public static const Isos:uint = 2;
		
		protected var array:Array = new Array();
		private var crc:Function;
		private var rad:Number;
				
		
		public function filter(color:uint, alpha:Number, blur:Number):void
		{
			array.push( new GlowFilter(color, alpha, blur, blur, 2, 1, false, false));
		}
		
		public function refresh():void
		{
			filters = array;
		}
		
		public function clear(n:uint=0):void
		{
			try
			{
				array.splice(n, array.length - n);
			}
			catch(err:Error){}
		}
	
		public static function circumIsos(n:Number):Number
		{
			var p0:GPoint = new GPoint(n, 0);
			var p1:GPoint = new GPoint(n/2, n);
			return (((p0.distance(p1) / Math.sin(p1.angle())))/2) + 1;
		}
	
		public static function circumCirc(n:Number):Number
		{
			return n+1;
		}
	
		public static function circumRect(n:Number):Number
		{
			return Math.sqrt(( (n * n)/ 2)) + 1;
		}
		
		public function circumscribe():GShape
		{
			var c:GShape = new GShape();
			c.draw(1, crc(rad), 1, Colors.Purple, .2, Colors.Purple, .1);
			c.alpha = 0;
			c.x = this.width / 2;
			c.y = this.height / 2; 
			return c;
		}
		
		public function draw(t:uint, n:Number, lt:Number, lc:uint, la:Number, fc:uint, fa:Number):void
		{
			rad = n;
			graphics.lineStyle(lt, lc, la);
			graphics.beginFill(fc, fa);
			
			switch(t)
			{
				case Rect:
					crc = circumRect;
					graphics.drawRect(0, 0, n, n);
					break;
				
				case Circ:
					crc = circumCirc;
					graphics.drawCircle(0, 0, n);
					break;
				
				case Isos:
					crc = circumIsos;
					graphics.moveTo(0, 0);
					graphics.lineTo(n, 0);
					graphics.lineTo(n/2, n);
					break;
			}
			graphics.endFill();
		}
	}
}
